<template>
  <div>
    <h1>瓦斯单单个人博客</h1>
    <div class="userBox">
      你好{{ username }}
      <el-button type="primary" plain @click="exit">退出</el-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: "",
    };
  },
  methods: {
    exit() {
      this.$confirm("确认退出登录?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "退出成功!",
          });
          localStorage.removeItem("token");
          this.$router.push("/login");
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消退出",
          });
        });
    },
  },
  mounted() {
    this.username = localStorage.getItem("username");
  },
};
</script>

<style lang="less" scoped>
h1 {
  font-size: 20px;
  float: left;
}
.userBox {
  float: right;
  margin-top: 25px;
}
.el-button {
  height: 25px;
  padding: 5px 10px;
}
</style>